//index.js
//获取应用实例
var app = getApp()
var utils = require('../../utils/util.js')
//创建精选页面对象
Page({

  data: {
    loading: false,
    loadtxt: '正在加载',
    currentId: '1001',
    banners: [],
    RollLink: [],
    AvatorText: [],
    newList: [
      { title:12312}
    ],
    section: [
      { name: '舞种',url:'../dance/dance', minname: 'Dance', id: '1001' }, { name: '视频',url:'../video/video', minname:'Video', id: '1032' },
      { name: '课程', minname: 'Course', url:'../course/course', id: '1003' }
    ],
      imgUrls: [
        // 'http://12059196.s21i-12.faiusr.com/2/ABUIABACGAAgucf6wgUojKG2JjCABTisAg!640x640.jpg',
        // 'http://12059196.s21i-12.faiusr.com/2/ABUIABACGAAgosv6wgUo2pLrIzCABTisAg!640x640.jpg',
        // 'http://12059196.s21i-12.faiusr.com/2/ABUIABACGAAgosv6wgUo2pLrIzCABTisAg!640x640.jpg'
        // 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
        // 'http://12059196.s21i-12.faiusr.com/2/ABUIABACGAAghuWOwgUo-ImbkgUwwAc4_gE.jpg',
          // 'http://12059196.s21i-12.faiusr.com/2/ABUIABACGAAggteOwgUo3rLuvwcwwAc4_gE.jpg',
          // 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
          // 'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
        '../../image/index/swiper1.jpg',
        '../../image/index/swiper1.jpg',
        '../../image/index/swiper1.jpg'
      ]
  },
  onLoad: function (params) {
wx.hideNavigationBarLoading()

  },
    //事件处理函数
    bindViewTap(e) {
        wx.navigateTo({
            url: '../detail/detail?id=' + e.target.dataset.id
        })
    },
    loadMore (e) {
        if (this.data.list.length === 0) return
        var date = this.getNextDate()
        var that = this
        that.setData({ loading: true })
        wx.request({
            url: 'http://news.at.zhihu.com/api/4/news/before/' + (Number(utils.formatDate(date)) + 1),
            headers: {
                'Content-Type': 'application/json'
            },
            success (res) {
                that.setData({
                    loading: false,
                    list: that.data.list.concat([{ header: utils.formatDate(date, '-') }]).concat(res.data.stories)
                })
            }
        })
    },

    getNextDate (){
        const now = new Date()
        now.setDate(now.getDate() - this.index++)
        return now
    },
    onLoad () {
        let that = this
        wx.request({
            url: 'http://news-at.zhihu.com/api/4/news/latest',
            headers: {
                'Content-Type': 'application/json'
            },
            success (res) {
                that.setData({
                    banner: res.data.top_stories,
                    list: [{ header: '今日热闻' }].concat(res.data.stories)
                })
            }
        })
        this.index = 1
        //调用应用实例的方法获取全局数据
        // app.getUserInfo(function(userInfo){
        //   //更新数据
        //   that.setData({
        //     userInfo:userInfo
        //   })
        // })

    }


});



